//
//  ViewController.m
//  UI20_豆瓣电影storyBoard
//
//  Created by 王阳阳 on 16/1/4.
//  Copyright © 2016年 www.lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "ViewController.h"
#import "ActiveTableViewCell.h"
#import "NetWorkHandler.h"
#import "activimodel.h"
#import "UIImageView+WebCache.h"
#import "activeViewController.h"
@interface ViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableview;

@property (nonatomic, strong)NSMutableArray *DataArr;

@end

@implementation ViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"活动";
    
        [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"bg.png"] forBarMetrics:UIBarMetricsDefault];
    

    [self data];
}

- (void)data
{
    NSString *path = @"http://project.lanou3g.com/teacher/yihuiyun/lanouproject/activitylist.php";
    [NetWorkHandler GETWithURL:path completion:^(id result) {
        NSArray *arr = result[@"events"];
        
        self.DataArr = [activimodel modelHandlerWithArray:arr];
        [self.tableview reloadData];
    }];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _DataArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ActiveTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
     activimodel *activ = _DataArr[indexPath.row];
    cell.MovieTitle.text = activ.title;
    cell.MovieAddress.text = activ.address;
    cell.Movietime.text = [activ.begin_time substringWithRange:NSMakeRange(5, 11)];
    cell.Movietype.text =activ.category_name;
    cell.MovieGanxingqu.text = activ.wisher_count.stringValue;
    cell.Moviecanjia.text = activ.participant_count.stringValue;
    [cell.Movieimage  sd_setImageWithURL:[NSURL URLWithString:activ.image]];
    cell.MOvieendtime.text = [activ.end_time substringWithRange:NSMakeRange(5, 11)];
    
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 250;
}


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    activeViewController *acti = segue.destinationViewController;
    acti.actie2 = _DataArr[_tableview.indexPathForSelectedRow.row];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
